package com.StarStudio.DAO;

import com.ruoyi.common.core.Entity.Goods;
import com.ruoyi.common.core.Entity.GoodsChooseResult;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
@SuppressWarnings("all")
public interface GoodsDAO {


    List<Goods> findGoodsList(Goods goods);

    List<Goods> findGoodsListByNormalStore(@Param("goods") Goods goods,@Param("LoginUserId") long LoginUserId);

    @Select("select * from goods where goods_id = #{id}")
    Goods findByGoods_id(long id);

//    @Delete("delete from goods where goods_id = #{id}")
    @Update("update goods set del_flag = true")
    void DeleteGoodsById(long id);

    @Insert("insert into goods values (null,#{store_id},#{goods_name},#{goods_describe},#{star},#{goods_price},#{market_price}," +
            "#{goods_main_picture},#{stock},#{exchange_deadline},#{attention},#{update_time},#{del_flag})")
    @Options(useGeneratedKeys = true,keyProperty = "goods_id",keyColumn = "goods_id")
    void addGoods(Goods goods);

    @Update("update goods set goods_name = #{goods_name},goods_describe = #{goods_describe},star = #{star},goods_price = #{goods_price}," +
            "market_price = #{market_price},goods_main_picture = #{goods_main_picture}," +
            "stock = #{stock}, exchange_deadline = #{exchange_deadline},attention = #{attention}, update_time = #{update_time}, " +
            "del_flag = #{del_flag} where goods_id = #{goods_id}")
    void updateGoods(Goods goods);

    @Select("select goods_id from goods where store_id = #{UserId}")
    List<Integer> getGoodsIdsByUserId(long UserId);

    @Select("select stock from goods where goods_id = #{goods_id}")
    int findStockByGoodsId(long goods_id);

    @Select("select count(0) from goods where del_flag = false")
    long findAllRecordNumber();

    @Select("select count(0) from goods where store_id = #{store_id} and del_flag = false")
    long findAllRecordNumberForNormalStore(long store_id);

    @Select("select g.* from goods g, goods_item git where git.goods_id = g.goods_id and git.item_id = #{goods_item_id}")
    Goods findByGoodsItemId(long goods_item_id);

    @Select("select goods_price from goods where goods_id = #{goods_id}")
    int findGoodsPriceByGoodsId(long goods_id);

    @Select("select goods_id,goods_name,goods_main_picture,stock from goods where del_flag = false")
    List<GoodsChooseResult> getGoodsChooseResultList();

    @Update("update goods set stock = #{newStock} where goods_id = #{goodsId}")
    void updateGoodsStockById(@Param("goodsId") long goodsId,@Param("newStock") int newStock);
}
